<template>
  <div>
    <h2>欢迎{{ user.name }}！您的 role 为{{ user.role }}</h2>
    <router-link to="/login">
      <el-button> 登出 </el-button>
    </router-link>
    <router-link to="/change-password">
      <el-button> 修改密码 </el-button>
    </router-link>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: {
        name: "",
        role: "",
      },
    };
  },
  mounted() {
    const user = sessionStorage.getItem("user");
    if (user) {
      this.user = JSON.parse(user);
      console.log('获取数据成功');
    }
    else {
      this.$router.push("/login");
    }
  }
};
</script>

<style scoped></style>